/*
 * NotManual.java
 *
 * Created on 3 de diciembre de 2008, 21:00
 */
package Vistas;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import java.util.Vector;
import Dominio.CtrlDominio;
import Dominio.NoEstaTemaException;
import Dominio.NoticiaNoValidaException;
import Dominio.Strouble;
import Dominio.VecTitTex;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.swing.ImageIcon;

/**
 *
 * @author  Sandra Crespo, Juan Manuel Fuentes Diaz 
 */
public class NotManual extends javax.swing.JFrame implements WindowListener {

    public double coin;
    private boolean guardar;
    private boolean bloqueado;
    private int idioma;
    private CtrlDominio CD = CtrlDominio.getInstance();
    private String archivoPath;
    private String titulo;
    private String texto;
    private String seccion;
    private Vector<String> palabrascl = new Vector<String>(0, 1);
    private Vector<Strouble> temas = new Vector<Strouble>(0, 1);
    private Vector<Strouble> temasPos = new Vector<Strouble>(0, 1); //temas posibles
    private Vector<Strouble> temasSeg = new Vector<Strouble>(0, 1); //temas seguros
    private Vector<FrecPal> palabras = new Vector<FrecPal>(0, 1);
    private static String[] cabecerasTemaPos = {"Temas Posibles", "Coincidencia(\u0025)"};
    private static String[] cabecerasTemaSeg = {"Temas Seleccionados", "Coincidencia(\u0025)"};
    private static String[] cabeceraPalabras = {"Palabras", "Frecuencia"};
    private static String[] cabeceraPalabrasCL = {"Palabras", "Frecuencia"};
    private String fs = System.getProperty("file.separator");
    private boolean addtema;

    /** Creates new form NotManual */
    public NotManual(int id) {
        idioma = id;
        initComponents();
        this.setLocationRelativeTo(null);
        jComboBox1.addItem("");jComboBox1.addItem("Deportes");
        jComboBox1.addItem("Nacional");jComboBox1.addItem("Internacional");jComboBox1.addItem("Economia");
        jComboBox1.addItem("Ciencia");jComboBox1.addItem("Espectaculos");jComboBox1.addItem("Salud");
        jComboBox1.addItem("Gente");
        jBtGuardar.setEnabled(false);
        coin = 0;
        Object[][] aux = new Object[0][0];
        jTemasPosibles.setModel(new javax.swing.table.DefaultTableModel(aux, cabecerasTemaPos));
        jTemasSeleccionados.setModel(new javax.swing.table.DefaultTableModel(aux, cabecerasTemaSeg));
        jPalabras1.setModel(new javax.swing.table.DefaultTableModel(aux, cabeceraPalabras));
        jPalabras.setModel(new javax.swing.table.DefaultTableModel(aux, cabeceraPalabras));
        this.setTitle("Clasificaci\u00F3n manual");
        ImageIcon ic = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "open.png");
        jButton1.setIcon(ic);
        ImageIcon ic2 = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "save.png");
        jBtGuardar.setIcon(ic2);
        ImageIcon ic3 = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "cancel.png");
        jBtCancelar.setIcon(ic3);
        ImageIcon ic4 = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "add.png");
        jBtAddTema.setIcon(ic4);
        ImageIcon ic5 = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "edit.png");
        jButton5.setIcon(ic5);
        ImageIcon ic6 = new ImageIcon(System.getProperty("user.dir") + fs + "src" + fs + "Image" + fs + "start.png");
        jButton2.setIcon(ic6);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTextField2 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTemasPosibles = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPalabras = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jPalabras1 = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTemasSeleccionados = new javax.swing.JTable();
        jBtAddTema = new javax.swing.JButton();
        jBtGuardar = new javax.swing.JButton();
        jBtCancelar = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));

        jTextField2.setText("(Archivo o direccion web)");

        jButton1.setText("Abrir archivo");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel1.setText("Archivo:");

        jButton2.setText("Clasificar");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jLabel6.setText("Seccion de la noticia:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(70, 70, 70)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 297, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jLabel6)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jLabel2.setText("Titulo:");

        jTextField3.setText("Titulo");

        jLabel3.setText("Temas:");

        jButton3.setText(">>");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jButton4.setText("<<");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        jTemasPosibles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jTemasPosibles.setName(""); // NOI18N
        jTemasPosibles.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTemasPosiblesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTemasPosibles);

        jPalabras.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jScrollPane3.setViewportView(jPalabras);

        jPalabras1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jScrollPane4.setViewportView(jPalabras1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTemasSeleccionados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jTemasSeleccionados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTemasSeleccionadosMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTemasSeleccionados);

        jBtAddTema.setText("Nuevo Tema");
        jBtAddTema.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jBtAddTemaMouseClicked(evt);
            }
        });

        jBtGuardar.setText("Guardar Clasificacion");
        jBtGuardar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jBtGuardarMouseClicked(evt);
            }
        });

        jBtCancelar.setText("Cancelar");
        jBtCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jBtCancelarMouseClicked(evt);
            }
        });

        jButton5.setText("Modificar minimo de coincidencia");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBtCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBtGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBtAddTema, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBtAddTema)
                .addGap(13, 13, 13)
                .addComponent(jButton5)
                .addGap(18, 18, 18)
                .addComponent(jBtGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBtCancelar)
                .addContainerGap(65, Short.MAX_VALUE))
        );

        jLabel4.setText("Palabras:");

        jLabel5.setText("Palabras clave:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(29, 29, 29)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton4)
                            .addComponent(jButton3))
                        .addGap(33, 33, 33)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 743, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addComponent(jLabel3)
                            .addGap(170, 170, 170)
                            .addComponent(jLabel4)
                            .addGap(113, 113, 113)
                            .addComponent(jLabel5)
                            .addContainerGap())
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addContainerGap()))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jButton3)
                        .addGap(36, 36, 36)
                        .addComponent(jButton4)
                        .addContainerGap())))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        if (!bloqueado) {
            javax.swing.JFileChooser filechooser = new javax.swing.JFileChooser();
            int returnVal = filechooser.showOpenDialog(jButton1);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = filechooser.getSelectedFile();
                archivoPath = file.getAbsolutePath();
                jTextField2.setText(file.getAbsolutePath());
            }
        }
    // TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        try {
            if (!bloqueado) {
                String st = new String(jTextField2.getText());
                VecTitTex vtt = new VecTitTex();
                if ((st.compareTo("(Archivo o direccion web)") != 0) && (st.compareTo("") != 0)&& !((String)jComboBox1.getSelectedItem()).equals("")) {
                    if (st.indexOf("http") != -1) {
                        JOptionPane.showMessageDialog(null, "La clasificacion de paginas web a traves de internet no es fiable al 100\u0025,\nya que depende del programador que haya dise�ado dicha pagina, por lo tanto los autores de este programa\nno se hacen responsables de posibles incosistencias y resultados negativos de la clasificacion.");
                        jBtGuardar.setEnabled(false);
                        guardar = false;
                        jBtAddTema.setEnabled(false);
                        addtema = false;
                    } else {
                        jBtGuardar.setEnabled(true);
                        guardar = true;
                        jBtAddTema.setEnabled(true);
                        addtema = true;
                    }
                    vtt = CD.clasificar(st);
                    FrecPal fp;
                    jTextField3.setText(vtt.tit);
                    this.titulo = vtt.tit;
                    this.texto = vtt.texto;
                    this.palabras = vtt.vec;
                    temasSeg = new Vector<Strouble>(0, 1);
                    Object[][] aux1 = new Object[vtt.palclave.size()][2];
                    for (int i = 0; i < vtt.palclave.size(); i++) {
                        fp = (FrecPal) vtt.palclave.get(i);
                        this.palabrascl.add(fp.pal);
                        aux1[i][0] = fp.pal;
                        aux1[i][1] = fp.frec;
                    }
                    jPalabras1.setModel(new javax.swing.table.DefaultTableModel(aux1, cabeceraPalabras));

                    Object[][] aux = new Object[vtt.vec.size()][2];
                    for (int i = 0; i < vtt.vec.size(); i++) {
                        fp = (FrecPal) vtt.vec.get(i);
                        aux[i][0] = fp.pal;
                        aux[i][1] = fp.frec;
                    }
                    jPalabras.setModel(new javax.swing.table.DefaultTableModel(aux, cabeceraPalabras));
                    seccion = (String)jComboBox1.getSelectedItem();
                    Vector<Strouble> stro = CD.sacaTemas(vtt, seccion);
                    Object[][] aux2 = new Object[stro.size()][2];
                    for (int i = 0; i < stro.size(); i++) {
                        if (stro.get(i).dist > coin) {
                            aux2[i][0] = stro.get(i).nom;
                            aux2[i][1] = stro.get(i).dist;
                        }
                    }
                    jTemasPosibles.setModel(new javax.swing.table.DefaultTableModel(aux2, cabecerasTemaPos));
                    temasPos = stro;
                    temas = stro;
                    actualizarTablas();
                } 
                else if(((String)jComboBox1.getSelectedItem()).equals("")){
                    JOptionPane.showMessageDialog(null, "Elige la seccion de la noticia.");
                }
                else {
                    JOptionPane.showMessageDialog(null, "Escribe la ubicaci\u00f3n del archivo o su direccion web.");
                    actualizarVentana();
                }
            }
        } catch (NoticiaNoValidaException e) {
            JOptionPane.showMessageDialog(null, "Noticia no v\u00e1lida");
            actualizarVentana();
        } catch (MalformedURLException e) {
            JOptionPane.showMessageDialog(null, "URL no v\u00e1lida");
            actualizarVentana();
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "Error de lectura/escritura");
            actualizarVentana();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            actualizarVentana();
        }
    }//GEN-LAST:event_jButton2MouseClicked

    private void actualizarVentana() {
        jTextField2.setText("(Archivo o direccion web)");
        jTextField3.setText("");
        Object[][] aux = new Object[2][2];
        jPalabras.setModel(new javax.swing.table.DefaultTableModel(aux, cabeceraPalabras));
    }

    private void jBtCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jBtCancelarMouseClicked
        if (!bloqueado) {
            int opcio = JOptionPane.showConfirmDialog(null, "Est\u00e1s a punto de salir de la clasificaci\u00f3n, \n          ¿est\u00e1s seguro?",
                    "¿Quieres salir?", JOptionPane.YES_NO_OPTION);
            if (opcio == 0) {
                this.dispose();
                //int idioma=2;
                new menu(idioma).setVisible(true);
            }
        }
}//GEN-LAST:event_jBtCancelarMouseClicked

    private void jBtAddTemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jBtAddTemaMouseClicked
        if (!bloqueado && addtema) {
            if (titulo == null) {
                JOptionPane.showMessageDialog(this, "No hay ninguna noticia abierta", "No has cargado ninguna ", JOptionPane.INFORMATION_MESSAGE);
            } else if (titulo.isEmpty()) {
                JOptionPane.showMessageDialog(this, "No hay ninguna noticia abierta", "No has cargado ninguna ", JOptionPane.INFORMATION_MESSAGE);
            } else {
                this.bloquearTodos();
                new AddTema(temas, temasPos, temasSeg, this).setVisible(true);
            }
        }
    }//GEN-LAST:event_jBtAddTemaMouseClicked

    private void jBtGuardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jBtGuardarMouseClicked
        if (!bloqueado && guardar) {
            titulo = jTextField3.getText();
            if (titulo == null) {
                JOptionPane.showMessageDialog(this, "No hay ninguna noticia abierta", "No has cargado ninguna ", JOptionPane.INFORMATION_MESSAGE);
            } else if (titulo.contains("  ") || titulo.endsWith(" ") || titulo.startsWith(" ")) {
                JOptionPane.showMessageDialog(this, "El t\u00edtulo de la noticia est\u00e1 en formato incorrecto", "T\u00edtulo incorrecto", JOptionPane.INFORMATION_MESSAGE);
            } else if (CD.estaDiccionarioNoticias(titulo)) {
                String t = "Ya hay una noticia con el t\u00edtulo " + titulo;
                JOptionPane.showMessageDialog(this, t, "Ya est\u00e1 en el diccionario", JOptionPane.INFORMATION_MESSAGE);
            } else {
                if (temasSeg.size() == 0) {
                    JOptionPane.showMessageDialog(this, "Tienes que seleccionar o crear al menos un tema", "No hay ning\u00fan tema seleccionado", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    int opcio = JOptionPane.showConfirmDialog(null, "¿Est\u00e1s seguro de guardar la clasificaci\u00f3n?", "Guardar la aplicaci\u00f3n", JOptionPane.YES_NO_OPTION);

                    if (opcio == 0) {
                        AuxNoticia aux = new AuxNoticia();
                        aux.path = archivoPath;
                        aux.palabras = palabras;
                        aux.seccion = seccion;
                        aux.palabrascl = palabrascl;
                        aux.texto = texto;
                        for (int i = 0; i < temasSeg.size() && temasSeg.get(i) != null; i++) {
                            aux.temas.add(temasSeg.get(i).nom);
                        }
                        aux.titulo = titulo;
                        CD.guardarClasificacionManual(aux);
                        try {
                            CD.guardarClasificacionManualXML(aux);
                        } catch (IOException e) {
                            JOptionPane.showMessageDialog(this, "Imposible guardar la noticia clasificada en XML, razon: " + e);
                        } catch (NoEstaTemaException e) {
                            JOptionPane.showMessageDialog(this, "Imposible guardar la noticia clasificada en XML, razon: " + e);
                        }
                        this.dispose();
                        new menu(idioma).setVisible(true);
                    }
                }
            }
        }
    }//GEN-LAST:event_jBtGuardarMouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        if (!bloqueado) {
            try {
                if (jTemasPosibles.getSelectedRow() != -1) {
                    Strouble s = new Strouble();
                    s.nom = (String) (jTemasPosibles.getValueAt(jTemasPosibles.getSelectedRow(), 0));
                    s.dist = (Double) (jTemasPosibles.getValueAt(jTemasPosibles.getSelectedRow(), 1));
                    temasSeg.add(s);
                    temasPos.remove(jTemasPosibles.getSelectedRow());
                    actualizarTablas();
                }
            } catch (NullPointerException e) {
                JOptionPane.showMessageDialog(null, "Campo nulo");
            }
        }// TODO add your handling code here:
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
        if (!bloqueado) {
            if (jTemasSeleccionados.getSelectedRow() != -1) {
                Strouble s = new Strouble();
                s.nom = (String) (jTemasSeleccionados.getValueAt(jTemasSeleccionados.getSelectedRow(), 0));
                s.dist = (Double) (jTemasSeleccionados.getValueAt(jTemasSeleccionados.getSelectedRow(), 1));
                if (!(s.dist >= coin)) {
                    JOptionPane.showMessageDialog(null, "Coincidencia menor que: " + coin + "%");
                } else {
                    temasPos.add(s);
                    temasSeg.remove(jTemasSeleccionados.getSelectedRow());
                    actualizarTablas();
                }
            }
        }
// TODO add your handling code here:
    }//GEN-LAST:event_jButton4MouseClicked

    private void jTemasPosiblesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTemasPosiblesMouseClicked
        if (!bloqueado) {
            try {
                if (evt.getClickCount() == 2) {
                    if (jTemasPosibles.getSelectedRow() != -1) {
                        Strouble s = new Strouble();
                        s.nom = (String) (jTemasPosibles.getValueAt(jTemasPosibles.getSelectedRow(), 0));
                        s.dist = (Double) (jTemasPosibles.getValueAt(jTemasPosibles.getSelectedRow(), 1));
                        temasSeg.add(s);
                        temasPos.remove(jTemasPosibles.getSelectedRow());
                        actualizarTablas();
                    }
                }
            } catch (NullPointerException e) {
                JOptionPane.showMessageDialog(null, "Campo nulo");
            }
        }
    }//GEN-LAST:event_jTemasPosiblesMouseClicked

    private void jTemasSeleccionadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTemasSeleccionadosMouseClicked
        if (!bloqueado) {
            if (evt.getClickCount() == 2) {
                if (jTemasSeleccionados.getSelectedRow() != -1) {
                    Strouble s = new Strouble();
                    s.nom = (String) (jTemasSeleccionados.getValueAt(jTemasSeleccionados.getSelectedRow(), 0));
                    s.dist = (Double) (jTemasSeleccionados.getValueAt(jTemasSeleccionados.getSelectedRow(), 1));
                    if (!(s.dist >= coin)) {
                        JOptionPane.showMessageDialog(null, "La coincidencia del tema es menor o igual que: " + coin + "%");
                    } else {
                        temasPos.add(s);
                        temasSeg.remove(jTemasSeleccionados.getSelectedRow());
                        actualizarTablas();
                    }
                }// TODO add your handling code here:
            }
        }
    }//GEN-LAST:event_jTemasSeleccionadosMouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        this.bloquearTodos();
        new Coincidencia(coin, this).setVisible(true);
    }//GEN-LAST:event_jButton5MouseClicked

    private int temaSize(Vector<Strouble> tema) {
        int j = 0;
        if (coin == 0) {
            return tema.size();
        } else {
            for (int i = 0; i < tema.size(); i++) {
                if (tema.get(i).dist > coin) {
                    j++;
                }
            }
        }
        return j;
    }

    public void actualizarTablas() {
        Object[][] aux;
        if (coin == 0) {
            aux = new Object[temasPos.size()][2];
            for (int i = 0; i < temasPos.size(); i++) {
                aux[i][0] = temasPos.get(i).nom;
                aux[i][1] = temasPos.get(i).dist;
            }
        } else {
            aux = new Object[temaSize(temasPos)][2];
            int j = 0;
            for (int i = 0; i < temasPos.size(); i++) {
                if (temasPos.get(i).dist > coin) {
                    aux[j][0] = temasPos.get(i).nom;
                    aux[j][1] = temasPos.get(i).dist;
                    j++;
                }
            }
        }
        jTemasPosibles.setModel(new javax.swing.table.DefaultTableModel(aux, cabecerasTemaPos));

        Object[][] aux2 = new Object[temasSeg.size()][2];
        for (int i = 0; i < temasSeg.size(); i++) {
            aux2[i][0] = temasSeg.get(i).nom;
            aux2[i][1] = temasSeg.get(i).dist;
        }
        jTemasSeleccionados.setModel(new javax.swing.table.DefaultTableModel(aux2, cabecerasTemaSeg));
    }

    public void activarBotones() {
        bloqueado = false;
        jButton1.setEnabled(true);
        jButton2.setEnabled(true);
        jButton3.setEnabled(true);
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jBtAddTema.setEnabled(true);
        jBtGuardar.setEnabled(true);
        jBtCancelar.setEnabled(true);
    }

    private void bloquearTodos() {
        bloqueado = true;
        jButton1.setEnabled(false);
        //jButton1.setVisible(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);
        jBtAddTema.setEnabled(false);
        jBtGuardar.setEnabled(false);
        jBtCancelar.setEnabled(false);

    }

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtAddTema;
    private javax.swing.JButton jBtCancelar;
    private javax.swing.JButton jBtGuardar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTable jPalabras;
    private javax.swing.JTable jPalabras1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTemasPosibles;
    private javax.swing.JTable jTemasSeleccionados;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowOpened(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosing(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosed(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowIconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeiconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowActivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeactivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
